package com.ysd.lis.service.sta.impl;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.ysd.common.Result;
import com.ysd.lis.dto.sta.StaModuleDto;
import com.ysd.lis.dto.sta.StaModuleParam;
import com.ysd.lis.entity.sta.StaModuleFundesc;
import com.ysd.lis.mapper.sta.StaModuleFundescMapper;
import com.ysd.lis.service.sta.StaModuleFundescService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * cold_chain.sys_module 服务实现类
 * </p>
 *
 * @author prs
 * @since 2024-12-27
 */
@Service
public class StaModuleFundescServiceImpl extends ServiceImpl<StaModuleFundescMapper, StaModuleFundesc> implements StaModuleFundescService {
    @Autowired
    StaModuleFundescMapper staModuleFundescMapper;
    @Override
    public Result findStaModuleFundescList(StaModuleParam param) {
        MPJLambdaWrapper<StaModuleFundesc> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.selectAll(StaModuleFundesc.class);
        if (StringUtils.isNotBlank(param.getStaModId())) {
            queryWrapper.eq(StaModuleFundesc::getStaId,param.getStaModId());
        }

        queryWrapper.eq(StaModuleFundesc::getDelFlag, 0)
                .orderByAsc(StaModuleFundesc::getSeq);
        return Result.succ(1, "查询成功", staModuleFundescMapper.selectList(queryWrapper));

    }

    @Override
    public Result saveOrUpdateStaModuleFundesc(StaModuleDto dto) {
        List<StaModuleFundesc> appraiseList = dto.getStaModuleFundescList();
        boolean b = this.saveOrUpdateBatch(appraiseList);
        if(b){
            return Result.succ(1, "成功", null);
        }else {
            return Result.fail(400,"失败","");
        }
    }

    @Override
    public Result batchDeleteStaModuleFundescList(StaModuleDto dto) {
        List<StaModuleFundesc> appraiseList = dto.getStaModuleFundescList();
        List<String> ids = appraiseList.stream().map(StaModuleFundesc::getId).collect(Collectors.toList());
        boolean b = this.removeByIds(ids);
        if(b){
            return Result.succ(1, "删除成功", null);
        }else {
            return Result.fail(400,"删除失败","");
        }
    }
}
